package com.lianrui.commons;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonIgnore;

public abstract class Page<T> {
	
	private int pageSize = 10;
	
	private int pageIndex = 1;
	
	private String orderBy;
	
	private int total;
	
	private int code;
	
	private String message;
	
	private List<T> result;
	
	@JsonIgnore
	private Map<String, String> expands = new HashMap<>();

	public int getPageSize() {
		return pageSize > 0 ? pageSize : 10;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPageIndex() {
		return pageIndex;
	}

	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}

	public String getOrderBy() {
		return orderBy;
	}

	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public List<T> getResult() {
		return result;
	}

	public void setResult(List<T> result) {
		this.result = result;
	}

	public Map<String, String> getExpands() {
		expands = expands == null ? new HashMap<String, String>() : expands;
		return expands;
	}

	public void setExpands(Map<String, String> expands) {
		this.expands = expands;
	}
	
	public Map<String, String> addExpands(String key, String value) {
		getExpands().put(key, value);
		return expands;
	}
	
	public int getStart() {
		return ((pageIndex < 1 ? 1 : pageIndex) - 1) * pageSize;
	}
	
	public int getEnd() {
		return getStart() + pageSize;
	}
	
}
